﻿#include "SongListView.h"
#include<qlist.h>
SongListView::SongListView(QWidget *parent)
	: QListView(parent)
{
	m_model = new QStandardItemModel(this);
	this->setModel(m_model);

	m_delegate = new MusicListDelegate(this);
	this->setItemDelegate(m_delegate);

	this->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);
	

	//m_model->appendRow(new QStandardItem(" "));
	//m_model->appendRow(new QStandardItem(" "));
	//m_model->appendRow(new QStandardItem(" "));
	//m_model->appendRow(new QStandardItem(" "));
	
	Song s1("张三"), s2("李四");
	s1.songName = "海阔天空";
	s1.duration_s = 120;

	s2.songName = "关山酒";
	s2.duration_s = 180;
	appendSong(s1);
	appendSong(s2);

	//插入一行，1，2，3，ListView只能看见列0的数据
	//m_model->appendRow({ new QStandardItem("1") ,new QStandardItem("2"),new QStandardItem("3") });

}

SongListView::~SongListView()
{}

void SongListView::appendSong(const Song & s,int index)
{
	QStandardItem* item = new QStandardItem;
	item->setData(index);
	item->setData(s.cover, Qt::UserRole + 1);
	item->setData(s.songName, Qt::UserRole + 2);
	item->setData(s.singerName, Qt::UserRole + 3);
	item->setData(s.duration_s, Qt::UserRole + 4);
	item->setData(s.url, Qt::UserRole + 5);
	m_model->appendRow(item);
}

